package com.meritdata.cloud.data.standard.desensitization.controller;

import com.meritdata.cloud.data.base.Page;
import com.meritdata.cloud.data.standard.desensitization.entity.TdDatamaskRule;
import com.meritdata.cloud.data.standard.desensitization.service.MaskService;
import com.meritdata.cloud.resultmodel.ResultBody;
import com.meritdata.cloud.resultmodel.ResultStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.Map;
//脱敏规则

@RequestMapping("/api/standard/mask")
@Controller
public class MaskController {
	
	@Autowired
	private MaskService service;
	
	@RequestMapping("/add")
	@ResponseBody
	public TdDatamaskRule add(@RequestParam String name, @RequestParam String config,
                              @RequestParam String example, @RequestParam String description){
		TdDatamaskRule ds = new TdDatamaskRule();
		ds.setName(name);
		ds.setConfig(config);
		ds.setExample(example);
		ds.setCreateTime(new Date());
		ds.setUpdateTime(new Date());
		ds.setDescription(description);
		ds.setEnable(1);
	//	ds.setId(UUID.randomUUID().toString().replaceAll("-",""));
		service.add(ds);
		return ds;
	}
	
	@RequestMapping("/page")
	@ResponseBody
	public Page<TdDatamaskRule> page(@RequestParam Map<String,Object> param){
		return service.page(param);
	}

	@RequestMapping("/enablelist")
	@ResponseBody
	public ResultBody enableList(){
		try {
			return ResultBody.success(service.enableList());
			//return null;
		} catch (RuntimeException e) {
			return ResultBody.failure(ResultStatus.DATA_OPERATION_ERROR, e);
		}


	}

	@RequestMapping("/del")
	@ResponseBody
	public Boolean  del(String ids){
		return service.del(ids);
	}
	@RequestMapping("/update")
	@ResponseBody
	public Boolean update(@RequestParam String id, @RequestParam String name, @RequestParam String config,
									@RequestParam String example,@RequestParam String description){
		return service.update(id,name,config,example,description);
	}
	@RequestMapping(value = "/update/state")
	@ResponseBody
	public Boolean  updateState(@RequestParam String ids,@RequestParam Integer state){
		return service.updateState(ids,state);
	}
}
